package org.example.mybatis.plus.dm8.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import org.example.mybatis.plus.dm8.entity.Person;
import org.example.mybatis.plus.dm8.service.PersonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/person")
public class PersonController {
    @Autowired
    private PersonService personService;

    @GetMapping
    public List<Person> list() {
        return personService.list();
    }

    @GetMapping("/{id}")
    public Person get(@PathVariable Long id) {
        return personService.getById(id);
    }

    @PostMapping
    public boolean save(Person person) {
        return personService.save(person);
    }

    @DeleteMapping("/{id}")
    public boolean delete(@PathVariable Long id) {
        return personService.removeById(id);
    }

    @GetMapping("/page")
    public IPage<Person> getUserPage(
            @RequestParam(defaultValue = "1") int current,
            @RequestParam(defaultValue = "3") int size) {
        return personService.getPersonPage(current, size);
    }
}
